#!/usr/bin/perl -w
# 
# Task D (4 points)
# Create a subroutine that takes an array and a number as arguments. 
# The subroutine should iterate over the array and divide each element 
# with the number. The result of the calculation should be printed to 
# the command prompt. Then write a program that defines an array 
# containing five numbers. Assume these represent expression values 
# of five genes. The program should then ask the user to give one number 
# as input and store it in a scalar variable. Finally, call the subroutine 
# and send the array and number as arguments.
#
# 
use warnings;
use strict;
#
sub theSub;
#
my @v, my $i;
# fill the array v with a random number between 0 and 100
for ($i = 0; $i<5; $i++){
    $v[$i] = int(rand(100));
}
# Get input 'n' from the user
print "Please give the number to use for the division of the array elements ";
my $n = <STDIN>;chomp($n);

# Call the subroutine that makes the divisions
theSub(\@v,$n);




sub theSub{
	# Get the array that was passed as a reference
	my $arrayRef = shift(@_);
	# Get the denominator
    my $number = shift(@_);
    # Dereference the array
    my @array = @{$arrayRef}; 
 
	my $i;
	# Loop through the array
    for ($i = 0; $i<$#array; $i++){
        # Write out the array element divided by the denominator
		$array[$i] = $array[$i]/$number;
		print("Array element with index $i divided by $number = $array[$i]\n")
	}
	# Return a reference to the array. This is not needed in this task.
	return \@array;
}
# 